﻿<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>分量顺序</title>
<script src="../js/global.js"></script>
<script type="text/javascript">

var uid=0;

	$(function() {
		init();
	})
	function init() {
		$("#askersTab").datagrid({
			url : 'getAskerAlls',
			method : 'post',
			pagination : true,
			singleSelect : true,
			toolbar:"#askersTabTools",
			queryParams : {
				checkInTime: $('#sercheckInTime').datebox('getValue')	
			}
			
		})
	}
	function formattercaozuo(value, row, index) {
		return "<a href='javascript:void(0)' onclick='set("
				+ index
				+ ")'>分配<a/>  <a href='javascript:void(0)' onclick='updateWeight("
				+ index + ")'>编辑权重<a/>"

	}
	var edit;
	function updateWeight(index) {
		edit=index;
		var datas = $("#askersTab").datagrid("getData");
		var row = datas.rows[index];
		//填充表单
		$("#updateWeightFrm").form("load",row);
		//打开弹窗
		$("#updateWeightDialog").dialog("open");
	}
	/* 取消编辑权重的对话框 */
	function updateWeightClose() {
		$('#updateWeightDialog').dialog("close");
	}
	function updateWeightSubmit() {
		var datas = $("#askersTab").datagrid("getData");
		var row = datas.rows[edit];
		 $.post("updateWeight", {
			askerId:row.askerId,
			weight : $("#weight").val(),
			bakContent : $("#bakContent").val()
		}, function(res) {
			if (res > 0) {
				$('#askersTab').datagrid('reload');
				$('#updateWeightDialog').dialog("close");
				$.messager.alert('提示', "修改成功!!!!")
			} else {
				$.messager.alert('提示', "修改失败!!!!")
			}
		}, "json") 
	}
	
	function formattercaozuostu(value, row, index) {
		return "<a href='javascript:void(0)' onclick='addStuToUser(" + index
				+ ")'>分配<a/>";
	}

	function addStuToUser(index) {
		var data = $("#allStu").datagrid("getData");
		var row = data.rows[index];
		var datas = $("#askersTab").datagrid("getSelected");
		$.messager.confirm("提示", "确认把此学生分配给该员工？", function(r) {
			if (r) {
				$.post("updateStuNetIdById", {
					id : row.id,
					uid:uid,
					netPusherId : datas.userid
				}, function(res) {
					if (res > 0) {
						$("#allStu").datagrid("reload");
						$.messager.alert("提示", "分配成功");
					} else {
						$.messager.alert("提示", "分配失败");
					}
				}, "json")
			}
		})
	}
	function set(index) {
		var data = $("#askersTab").datagrid("getData");
		var row = data.rows[index];
		uid=row.userid;
		//allStu	
		$("#setFrm").window("setTitle", "正在设置" + row.askerName + "权限信息");
		$("#allStu").datagrid({
			url : "getStuAll",
			method : "post",
			singleSelect : true,
		});
		$("#setFrm").window("open");
	}
	
	function shuaxin(){
		$("#askersTab").datagrid({
			url : 'getAskerAlls',
			method : 'post',
			pagination : true,
			singleSelect : true,
			toolbar:"#askersTabTools",
			queryParams : {
				checkInTime:""	
			}
			
		})
	}
</script>
</head>
<body>
<div id="askersTabTools">
签到时间:<input type="text" class="easyui-datebox" id="sercheckInTime">
<a href="javascript:void(0)" onclick="init()"
			class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
			<a href="javascript:void(0)" onclick="shuaxin()"
			class="easyui-linkbutton" data-options="iconCls:'icon-reload'">刷新</a>
</div>
	<table id="askersTab" class="easyui-datagrid">
		<thead>
			<tr>
				<th data-options="field:'askerId',title:'访问者编号'"></th>
				<th data-options="field:'askerName',title:'用户名'"></th>
				<th data-options="field:'roleName',title:'用户角色'"></th>
				<th data-options="field:'checkInTime',title:'签到时间'"></th>
				<th data-options="field:'weight',title:'权重'"></th>
				<th data-options="field:'bakContent',title:'备注'"></th>
				<th
					data-options="field:'caozuo',title:'操作',formatter:formattercaozuo"></th>
		</thead>
	</table>

	<div id="setFrm" class="easyui-window"
		data-options="modal:true,closed:true"
		style="width: 500px; height: 600px;">
		<table>
			<tr>
				<td width="500px">
					<table id="allStu" class="easyui-datagrid"
						data-options="title:'尚未分配的学生',singleSelect:true">
						<thead>
							<tr>
								<th data-options="field:'id'">学生编号</th>
								<th data-options="field:'name'">学生名称</th>
								<th data-options="field:'caozuo',formatter:formattercaozuostu">操作</th>
							</tr>
						</thead>
					</table>
				</td>
			</tr>
		</table>
	</div>
	
<!-- 编辑权重字段 -->
<!-- 	<div id="updateWeightDialog" class="easyui-dialog"
		data-options="modal:true,closed:true">
		<form id="updateWeightFrm" class="easyui-form">
			<table>
				<tr>
					<td><label for="name">权重:</label></td>
					<td><input class="easyui-textbox" type="text" id="weight"
						name="weight" /></td>
				</tr>

				<tr>
					<td><label for="name">备注:</label></td>
					<td><input class="easyui-validatebox" type="text"
						id="bakContent" name="bakContent" /></td>
				</tr>
				<tr>
					<td><a href="javascript:void(0)" class="easyui-linkbutton"
						onclick="updateWeightSubmit()">提交</a></td>
					<td><a href="javascript:void(0)" class="easyui-linkbutton"
						onclick="updateWeightClose()">取消</a></td>
				</tr>
			</table>
		</form>

	</div> -->
	
	<div id="updateWeightDialog" class="easyui-dialog"
		data-options="modal:true,closed:true,title:'编辑权重',buttons:[{
				text:'保存',
				iconCls:'icon-save',
				handler:function(){
				updateWeightSubmit()
				}
			},{
				text:'取消',
				iconCls:'icon-clear',
				handler:function(){
				updateWeightClose()
				}
			}]">
		<form id="updateWeightFrm">
			<table cellspacing="5">
				<tr>
					<td>权重：</td>
					<td><input class="easyui-textbox" type="text" id="weight"
						name="weight" /></td>
				</tr>
				<tr>
					<td>备注：</td>
					<td><input class="easyui-textbox" type="text" id="bakContent"
						name="bakContent" /></td>
				</tr>
			
			</table>
		</form>
	</div>
</body>
</html>